//
//  FocusDoctorController.m
//  KMedicine
//
//  Created by 曹牧 on 16/7/5.
//  Copyright © 2016年 caomu. All rights reserved.
//

#import "FocusDoctorController.h"
#import "AkuFocusDoctorModel.h"
#import "AkuFocusDoctorCell.h"
#import "AkuDoctorMessage.h"

@interface FocusDoctorController ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) NSArray *dataArray;

@end

@implementation FocusDoctorController

- (NSArray *)dataArray {
    
    if (!_dataArray) {
        
        NSArray *testData = @[@{@"name":@"王小刚",@"position":@"院长",@"hospital":@"北京协和医院",@"cen":@(34),@"le":@(23),@"ri":@(34)},
                              @{@"name":@"王小刚",@"position":@"院长",@"hospital":@"北京协和医院",@"cen":@(34),@"le":@(23),@"ri":@(34)},
                              @{@"name":@"王小刚",@"position":@"院长",@"hospital":@"北京协和医院",@"cen":@(34),@"le":@(23),@"ri":@(34)},
                              @{@"name":@"王小刚",@"position":@"院长",@"hospital":@"北京协和医院",@"cen":@(34),@"le":@(23),@"ri":@(34)},
                              @{@"name":@"王小刚",@"position":@"院长",@"hospital":@"北京协和医院",@"cen":@(34),@"le":@(23),@"ri":@(34)},
                              @{@"name":@"王小刚",@"position":@"院长",@"hospital":@"北京协和医院",@"cen":@(34),@"le":@(23),@"ri":@(34)},
                              @{@"name":@"王小刚",@"position":@"院长",@"hospital":@"北京协和医院",@"cen":@(34),@"le":@(23),@"ri":@(34)},
                              @{@"name":@"王小刚",@"position":@"院长",@"hospital":@"北京协和医院",@"cen":@(34),@"le":@(23),@"ri":@(34)},
                              @{@"name":@"王小刚",@"position":@"院长",@"hospital":@"北京协和医院",@"cen":@(34),@"le":@(23),@"ri":@(34)},
                              @{@"name":@"王小刚",@"position":@"院长",@"hospital":@"北京协和医院",@"cen":@(34),@"le":@(23),@"ri":@(34)},
                              @{@"name":@"王小刚",@"position":@"院长",@"hospital":@"北京协和医院",@"cen":@(34),@"le":@(23),@"ri":@(34)},
                              @{@"name":@"王小刚",@"position":@"院长",@"hospital":@"北京协和医院",@"cen":@(34),@"le":@(23),@"ri":@(34)},
                              @{@"name":@"王小刚",@"position":@"院长",@"hospital":@"北京协和医院",@"cen":@(34),@"le":@(23),@"ri":@(34)},
                              @{@"name":@"王小刚",@"position":@"院长",@"hospital":@"北京协和医院",@"cen":@(34),@"le":@(23),@"ri":@(34)},
                              @{@"name":@"王小刚",@"position":@"院长",@"hospital":@"北京协和医院",@"cen":@(34),@"le":@(23),@"ri":@(34)},
                              @{@"name":@"王小刚",@"position":@"院长",@"hospital":@"北京协和医院",@"cen":@(34),@"le":@(23),@"ri":@(34)},
                              @{@"name":@"王小刚",@"position":@"院长",@"hospital":@"北京协和医院",@"cen":@(34),@"le":@(23),@"ri":@(34)},
                              @{@"name":@"王小刚",@"position":@"院长",@"hospital":@"北京协和医院",@"cen":@(34),@"le":@(23),@"ri":@(34)},
                              @{@"name":@"王小刚",@"position":@"院长",@"hospital":@"北京协和医院",@"cen":@(34),@"le":@(23),@"ri":@(34)},
                              @{@"name":@"王小刚",@"position":@"院长",@"hospital":@"北京协和医院",@"cen":@(34),@"le":@(23),@"ri":@(34)},
                              @{@"name":@"王小刚",@"position":@"院长",@"hospital":@"北京协和医院",@"cen":@(34),@"le":@(23),@"ri":@(34)},
                              @{@"name":@"王小刚",@"position":@"院长",@"hospital":@"北京协和医院",@"cen":@(34),@"le":@(23),@"ri":@(34)},
                              @{@"name":@"王小刚",@"position":@"院长",@"hospital":@"北京协和医院",@"cen":@(34),@"le":@(23),@"ri":@(34)},
                              @{@"name":@"王小刚",@"position":@"院长",@"hospital":@"北京协和医院",@"cen":@(34),@"le":@(23),@"ri":@(34)}];
        
        NSMutableArray *mut = [NSMutableArray array];
        
        for (NSDictionary *dict in testData) {
            
            AkuFocusDoctorModel *model = [AkuFocusDoctorModel focusDoctorModelWithDict:dict];
         
            [mut addObject:model];
        }
        _dataArray = mut.copy;
        
    }
    return _dataArray;
}

- (void)viewDidLoad {
    [super viewDidLoad];


    UITableView *table = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];

    table.tableFooterView = [[UIView alloc] init];

    table.delegate = self;
    table.dataSource = self;
    
    [table registerClass:[AkuFocusDoctorCell class] forCellReuseIdentifier:@"cell"];
    
    [self.view addSubview:table];
    
    NSURL *url = [NSURL URLWithString:@"http://iosapi.itcast.cn/carelinkQuickLogin.json.php"];
    
    /*
     请求地址: http://iosapi.itcast.cn/addDoctor.json.php
     请求参数:{"user_id":1000089,"doctor_id":300000315}
     */
    
    
    /*
     http://iosapi.itcast.cn/carelinkQuickLogin.json.php
     请求参数:{"login_token":"985c96ce43bb5ef69de3e1ad8afaa83f"}
     */
    
    NSDictionary *dict = @{@"login_token":@"985c96ce43bb5ef69de3e1ad8afaa83f"};
    
    
    
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    
    request.HTTPMethod = @"POST";
    request.HTTPBody = [NSJSONSerialization dataWithJSONObject:dict options:0 error:NULL];
    
//    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse * _Nullable response, NSData * _Nullable data, NSError * _Nullable connectionError) {
//        
//        if(connectionError){
//            NSLog(@"conn erro ");
//            return;
//        }
//        
//        NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
//        if(httpResponse.statusCode ==200 || httpResponse.statusCode == 304){
//            
//            NSString *string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
//            NSLog(@"%@",string);
//            
//        }else{
//            NSLog(@"error");
//        }
//        
//    }];
    
    /*
     
     
     {
     "msg":"OK",
     "data":{
     "easymob_id":"d300000315",
     "doctor_id":300000315,
     "hospital_name":"北京协和医院",
     "doctor_portrait":"http://iosapi.itcast.cn/image/2093000003151445677716555.jpg",
     "flower":0,
     "doctor_title_id":0,
     "doctor_title_name":"心理医生",
     "banner":0,
     "doctor_name":"何晔鑫",
     "doctor_attention_id":194,
     "hospital_id":1,
     "operation_count":0,
     "doctor_gender":1
     },
     "code":0
     }
     
     
     */
    
    

}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return self.dataArray.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    AkuFocusDoctorCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    
    AkuFocusDoctorModel *model = self.dataArray[indexPath.row];
    
    cell.focusDoctorCellmodel = model;
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    return 100;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    AkuFocusDoctorModel *model = self.dataArray[indexPath.row];
    
    AkuDoctorMessage *MessageControl = [[AkuDoctorMessage alloc]init];
    MessageControl.focusDoctorCellmodel = model;
    
    [self.navigationController pushViewController:MessageControl animated:YES];
}


@end














